<?php
App::uses('Controller', 'Controller');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
App::uses('ComponentCollection', 'Controller');
App::uses('Hungdv7GuessGameComponent', 'Controller/Component');
App::uses ( 'CsvIterator', 'ZCommon' );

class TestGuessGameController extends Controller {
	public $guess = null;
}

class Hungdv7GuessGameComponentTest extends CakeTestCase{
	public $GuessGameComponent = null;
	public $Controller = null;
	
	public function setUp(){
		parent::setUp(); 
		
		$Collection = new ComponentCollection();
		$this->GuessGameComponent = new Hungdv7GuessGameComponent($Collection); 
		$CakeRequest = new CakeRequest();
		$CakeResponse = new CakeResponse();
		$this->Controller = new TestGuessGameController($CakeRequest, $CakeResponse);
		$this->GuessGameComponent->startup($this->Controller);
	}
	
	/**
	 * @dataProvider provider
	 */
	public function testPlay($price, $g1, $g2, $g3, $g4, $expected){
		//test play with different sets of parameters
		//test case 1
		$result = $this->GuessGameComponent->play($price, $g1, $g2, $g3, $g4);		
		/* print_r($result . ' --- ' . $expected);
		exit; */
		$this->assertEqual($result, $expected);
	}
	
	public function provider() {
		$file = TMP . 'tests/hungdv7.csv';
		$arr_data = new CsvIterator ( $file );
		
		// convert iterator to array, remove null element, reindex
		$arr_data = array_values ( array_filter ( iterator_to_array ( $arr_data ) ) );
		
		// remove first element - for column title
		array_shift ( $arr_data );
		return $arr_data;
	}
	
	public function tearDown(){
		parent::tearDown();
		//clean up after test
		unset($this->GuessGameComponent);
		unset($this->Controller);
	}
	
	
	
}

